#include "kernel/cell.hpp"
#include "yocto/lua/lua-config.hpp"
#include "yocto/ios/ocstream.hpp"

void Cell:: simpleProtonRate( lua_State *L )
{

	const Real V_AE  = pAE->V;
	const Real V_NHE = pNHE->V;
	
	const Real K1    = Lua::Config::Get<lua_Number>(L,"K1");
	const Real KH    = Lua::Config::Get<lua_Number>(L,"K_Henry");
	const Real PCO2  = 40.0/760;
	const Real kappa = (K1/KH) * PCO2;
	const Real Kw    = Lua::Config::Get<lua_Number>(L,"Kw");
	const Real Kr    = pNHE->Kr;
	
	std::cerr << "kappa=" << kappa << std::endl;
	
	ios::ocstream fp("hsimple.dat",false);
	for( Real pH = 6.7; pH <= 7.7; pH += 0.001 )
	{
		const Real h       = Pow(10.0,-pH);
		const Real h2      = h*h;
		const Real Theta   = h2 / ( Kw+kappa+h2); 
		const Real b       = kappa/h;
		const Real rho_AE  = V_AE * pAE->Sigma(b);
		const Real rho_NHE = V_NHE * pNHE->Sigma(h/Kr);
		const Real rate    = Theta * ( rho_AE - rho_NHE );
		fp("%g %g %g\n", h, rate, pH );
	}

}

